﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace PoemonAdventures
{
    class GameScreen
    {
        KeyboardState keyState;
        KeyboardState prevKeyState;
        Player player;
        Poemon enemy;
        Camera2D camera;
        ScreenManager screenManager;

        public GameScreen(ScreenManager screenManager)
        {
            this.screenManager = screenManager;
            player = new Player(screenManager.Content.Load<Texture2D>("vnz136"), screenManager.Content.Load<Texture2D>("enemy1monkey"), new Vector2(250, 250));
            enemy = new Poemon(screenManager.Content.Load<Texture2D>("enemy1monkey"));
            camera = new Camera2D();
        }

        public void Update(GameTime gameTime)
        {
            prevKeyState = keyState;
            keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.F) && keyState != prevKeyState)
            {
                screenManager.Fight(new FightScreen(player, enemy));
            }
            if (keyState.IsKeyDown(Keys.Back) && keyState != prevKeyState && ScreenManager.gameState == GameState.Fight)
            {
                ScreenManager.gameState = GameState.Map;
            }
            if (keyState.IsKeyDown(Keys.Q) && keyState != prevKeyState && ScreenManager.gameState == GameState.Map)
            {
                ScreenManager.gameState = GameState.Menu;
            }
            player.Update();
            camera.Update();
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, camera.TransformMatrix);
            if (ScreenManager.gameState == GameState.Map)
            {
                player.Draw(spriteBatch);
                spriteBatch.DrawString(ScreenManager.osdFont, "MAP, press \"F\" to fight, \"Q\" to quit", new Vector2(10, 10), Color.Black);
            }
            spriteBatch.End();
        }
    }
}